package com.hzmall.controller.backend;

import com.hzmall.common.ServerResponse;
import com.hzmall.pojo.User;
import com.hzmall.service.impl.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = "/manage/user/")
public class UserBackendController {

    @Autowired
    private UserService userService;

    //后台管理员登录
    @RequestMapping(value = "login.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse login(HttpServletRequest request, HttpSession session, HttpServletResponse response,String username, String password){
        if (StringUtils.isBlank(username) || StringUtils.isBlank(password)){
            return ServerResponse.createByErrorMessage("用户名或密码不能为空");
        }
        return this.userService.adminLogin(request,username,session,password,response);
    }

    //用户列表
    @RequestMapping(value = "list.do")
    @ResponseBody
    public ServerResponse list(@RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum){
        return this.userService.list(pageNum, pageSize);
    }


}
